import http.cookiejar
import urllib.request

# cookie练习
# cookie = http.cookiejar.CookieJar()
# handler = urllib.request.HTTPCookieProcessor(cookie)
# opener = urllib.request.build_opener(handler)
# response = opener.open('http://www.baidu.com')
# for i in cookie:
#     print(i.name+'='+i.value)

# test2
filename = 'LWPC_cookie.txt'
# cookie = http.cookiejar.MozillaCookieJar(filename)  #保存格式区别
cookie = http.cookiejar.LWPCookieJar(filename)
handler = urllib.request.HTTPCookieProcessor(cookie)
opener = urllib.request.build_opener(handler)
response = opener.open('http://www.baidu.com')
cookie.save(ignore_discard=True, ignore_expires=True)
